package com.api.projects.service.inner;

import com.api.apicommon.model.entity.InterfaceInfo;
import com.api.apicommon.service.InnerInterfaceInfoService;
import com.api.projects.common.ErrorCode;
import com.api.projects.exception.BusinessException;
import com.api.projects.mapper.InterfaceInfoMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * 为dubbo提供服务
 */
@DubboService
public class InnerInterfaceInfoSerImpl implements InnerInterfaceInfoService {
    //拿到接口的Dao层
    @Resource
    private InterfaceInfoMapper interfaceInfoMapper;

    /**
     * 根据请求地址，查询接口信息
     * @param url : 请求地址
     * @param method : 请求方法
     * @return
     */
    @Override
    public InterfaceInfo getInterfaceInfo(String url, String method) {
        if(StringUtils.isAnyBlank(url,method)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("url",url);
        queryWrapper.eq("method",method);
        return interfaceInfoMapper.selectOne(queryWrapper);

    }
}
